package com.hd.crdao.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.bean.ShopListBean;
import com.hd.crdao.utils.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 *@author Administrator
 *@date 2017/7/28 0028
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    public List<ShopListBean.ListAreaBean> mlistArea;

    public MyAdapter(List<ShopListBean.ListAreaBean> listArea) {
        this.mlistArea = listArea;
    }

    private OnMyItemClickListener listener;

    public void setOnMyItemClickListener(OnMyItemClickListener listener) {
        this.listener = listener;

    }

    public interface OnMyItemClickListener {
        void myClick(View v, int pos);

        void mLongClick(View v, int pos);
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = View.inflate(UIUtils.getContext(), R.layout.recyclerview_item, null);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.mTv.setText((mlistArea.get(position).getName()));
        if (listener != null) {
            holder.mTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.myClick(v, holder.getAdapterPosition());
                }
            });


            // set LongClick
            holder.mTv.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    listener.mLongClick(v, holder.getAdapterPosition());
                    return true;
                }
            });

        }
    }


    @Override
    public int getItemCount() {
        return mlistArea.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv)
        TextView mTv;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
